<?php 
//print_r($page);

$cs = Yii::app ()->getClientScript (); 
$cs = Yii::app ()->getClientScript()->registerCoreScript ('jquery'); 
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/jquery-ui-1.8.7.custom.min.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JWidget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JTextWidget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JWeiboWidget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JImageWidget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/colorpicker.js");
$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/jui/jquery-ui-1.8.11.custom.css");
$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/colorpicker/colorpicker.css");
$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/jwidget.css");

?>
<div id='my_page'>
 
<script>
<?php 
if($page){
	foreach($page->widgets() as $widget){
		$widget->_id = $widget->_id.'';
		echo "new ".$widget['fields']['jClass']."(".json_encode($widget).");";
		
	}
}
?> 
</script>
<?php 
//
//foreach($page->widgets() as $widget){
//	
//	$class =  $widget['fields']['jClass'];
//	
//	switch($class){ 
//		case 'JImageWidget':
//			foreach($widget['styles'] as $key => $val){
//				$style .=$key.':'.$val.';';
//			}
//			
//			echo CHtml::image( $widget['fields']['src'],'',array('style' => $style) );
//			
//			break;
//		case 'JTextWidget':
//		default:
//			$text = isset($widget['fields']['text'])?$widget['fields']['text']:false;
//			$style =  '';
//			foreach($widget['styles'] as $key => $val){
//				$style .=$key.':'.$val.';';
//			}
//			
//			echo CHtml::tag( $widget['fields']['tag'],array('style' => $style), $text );
//	}
//	
//}








?>















</div>